<?php
	$ls_gridname	= 'dtl_sample2';


// ----------------- >> Form Detail << ----------------- ?>
<script type="text/javascript">
	$(document).ready(function(){
		
		// Setup Form
		$('#form_<?php echo $ls_gridname; ?>').setupForm([
			{ name: 'urutan', type:'numeric', precision:0 },
			{ name: 'tanggal_pembayaran', type: 'date', size: 'short', maxlength: 20 },
			{ name: 'nama_tenant', type: 'lov', size: 'short',
				onClearButton:function(){
					$(this).setval(''); 
					$('#no_tenant').setval(''); 
					$('#<?php echo $ls_gridname; ?>_no_tenant').setval('');
				},
				onActionButton:function(){ 
					LOVTenant({ onSelect:function(row){ 
						$('#<?php echo $ls_gridname; ?>_nama_tenant').setval(row.nama_tenant); 
						$('#<?php echo $ls_gridname; ?>_no_tenant').setval(row.no_tenant); 
					} }); 
				}
			},
			{ name: 'kode_barang', type: 'text', size: 'short', maxlength: 10, noempty:true },
			{ name: 'kemasan', type: 'text', size: 'medium', maxlength: 20 },
			{ name: 'kemasan_besar', type: 'text', size: 'medium', maxlength: 20 },
			{ name: 'satuan_besar', type: 'text', size: 'medium', maxlength: 20 },
			{ name: 'jumlah_pesanan', type: 'text', size: 'medium', maxlength: 20 },
			{ name: 'jumlah_kirim', type: 'text', size: 'medium', maxlength: 20 },
			{ name: 'jumlah_terima', type: 'text', size: 'medium', maxlength: 20 },
			{ name: 'harga_pokok', type: 'text', size: 'medium', maxlength: 20 },
			{ name: 'harga_jual', type: 'text', size: 'medium', maxlength: 20 },
			{ name: 'terima', type: 'text', size: 'medium', maxlength: 20 },
			{ name: 'catatan', type: 'textarea', size: 'medium', maxlength: 20 },
			//{ name: 'qty_order', type: 'numeric', precision:2 }
		], {}, { prefix:'<?php echo $ls_gridname; ?>_' });
		
		// Set Hidden Object
		$('#<?php echo $ls_gridname; ?>_urutan').hide();
		
		// Create Dialog
		$('#form_<?php echo $ls_gridname; ?>_container').dialog({
			closed:true,
			modal:true,
			title: '_',
			width:550,
			height: 300,
			buttons:[{
				text:'Save',
				iconCls:'icon-save',
				handler:function(){
					var ls_mode			= $('#form_<?php echo $ls_gridname; ?>').data('mode');
					var row				= formToJSON('form_<?php echo $ls_gridname; ?>');
					var ls_error		= '';
					
					/*// Validasi
					
					if(row.kd_barang == ''){
						ls_error	+= 'Isi Barang\n';
					}
					if(row.qty_order == 0){
						ls_error	+= 'Isi Jumlah Barang\n';
					}*/
					
					// Eksekusi
					if(ls_error!=''){
						$.messager.alert('Error', nl2br(ls_error), 'error');
					}else{
						if(ls_mode=='create'){
							$('#<?php echo $ls_gridname; ?>').datagrid('appendRow', row );
							$('#form_<?php echo $ls_gridname; ?>_container').dialog('close');
						} else {
							var selectedIndex = $('#<?php echo $ls_gridname; ?>').data('selectedIndex');
							
							updateRowFlag('<?php echo $ls_gridname; ?>', row); // Patching Flag Update
							$('#<?php echo $ls_gridname; ?>').datagrid('updateRow',{index:selectedIndex,row:row});
							
							$('#form_<?php echo $ls_gridname; ?>_container').dialog('close');
							jsonToForm(oSel, {prefix:'<?php echo $ls_gridname; ?>_'});
							$('#<?php echo $ls_gridname; ?>_no_detail_tagihan').val( $('#<?php echo $ls_gridname; ?>_no_detail_tagihan').val() );
						}
					}
				}
			},{
				text:'Close',
				iconCls:'icon-cancel',
				handler:function(){
					$('#form_<?php echo $ls_gridname; ?>_container').dialog('close');
				}
			}]
		});
	});
</script>
<div id="form_<?php echo $ls_gridname; ?>_container" style="padding:5px;width:600px;height:400px;">
	<div id="form_<?php echo $ls_gridname; ?>">
    <table class="tb_form" style="width:100%;" cellpadding="0" cellspacing="0">
    <tr>
        <td class="label" style="width:150px">Kode Barang</td>
        <td><select id="kode_barang" name="kode_barang">
				<option value="Ada"></option>
				<option value="Tidak Tahu">Cabang 2</option>
				<option value="Sebagian">Cabang 3</option>
			</select></td>
    </tr>
    <tr>
        <td class="label">Kemasan</td>
        <td><input id="kemasan" /></td>
    </tr>
    <tr>
        <td class="label">Kemasan Besar</td>
        <td><input id="kemasan_besar" /></td>
    </tr>
    <tr>
        <td class="label">Satuan Besar</td>
        <td><input id="satuan_besar" /></td>
    </tr>
    <tr>
        <td class="label">Jumlah Pesanan</td>
        <td><input id="jumlah_pesanan" /></td>
    </tr>
    <tr>
        <td class="label">Jumlah Kirim</td>
        <td><input id="jumlah_kirim" /></td>
    </tr>
    <tr>
        <td class="label">Jumlah Terima</td>
        <td><input id="jumlah_terima" /></td>
    </tr>
    <tr>
        <td class="label">Harga Pokok</td>
        <td><input id="harga_pokok" /></td>
    </tr>
    <tr>
        <td class="label">Harga Jual</td>
        <td><input id="harga_jual" /></td>
    </tr>
    <tr>
        <td class="label" style="width:150px">Terima</td>
        <td><select id="terima" name="opsi">
				<option value="Ada"></option>
				<option value="Tidak Tahu">Cabang 2</option>
				<option value="Sebagian">Cabang 3</option>
			</select></td>
    </tr>
    <tr>
        <td class="label">Catatan</td>
        <td><input id="catatan" name="catatan" /></td>
    </tr>
    </table>
	</div>
</div>
<?php 



// ----------------- >> Table Detail << ----------------- ?>
<script type="text/javascript">
	$(document).ready(function(){
		$('#<?php echo $ls_gridname; ?>').datagrid({
			url:gs_path+'/'+controller+'/<?php echo $ls_gridname; ?>_data',
			queryParams:{ no_detail_tagihan:$('#no_tagihan_listrik').getval(), rows:9999999999 }, //$('#kode_desain').getval()
			<?php if($mode!='view'){ 
			// -->> Toolbar [Start]
			// Only Appear On Mode Create / Edit ?>
			toolbar:[{
				text:'Tambah',
				iconCls:'icon-add',
				handler:function(){
					resetError();
					
					$('#form_<?php echo $ls_gridname; ?>_container').dialog('open');
					$('#form_<?php echo $ls_gridname; ?>').data('mode', 'create');
					$('#form_<?php echo $ls_gridname; ?>_container').prev().find('.panel-title').html('Tambah Detail Desain');					
					$('#form_<?php echo $ls_gridname; ?>').resetForm();
				}
			},'-',{
				text:'Ubah',
				iconCls:'icon-edit',
				handler:function(){
					var oSel=$('#<?php echo $ls_gridname; ?>').datagrid('getSelected'); 
					if(oSel==null){ $.messager.alert('&nbsp;', gs_msg_row_unselected, 'warning'); }
					else{ 
						resetError();
						
						$('#form_<?php echo $ls_gridname; ?>_container').dialog('open');
						$('#form_<?php echo $ls_gridname; ?>').data('mode', 'edit');
						$('#form_<?php echo $ls_gridname; ?>_container').prev().find('.panel-title').html('Ubah Detail Desain');
						
						jsonToForm(oSel, {prefix:'<?php echo $ls_gridname; ?>_'});
					}
				}
			},'-',{
				text:'Hapus',
				iconCls:'icon-remove',
				handler:function(){
					var row = $('#<?php echo $ls_gridname; ?>').datagrid('getSelected');
					if(row==null){ $.messager.alert('&nbsp;', gs_msg_row_unselected, 'warning'); }
					else if(row){
						if(!confirm('Hapus baris data?')) return false;

						var index = $('#<?php echo $ls_gridname; ?>').datagrid('getRowIndex', row);
						$('#<?php echo $ls_gridname; ?>').datagrid('deleteRow', index);
					}
				}
			}],<?php 
			} // -->> Toolbar [End]
			?>
			onClickRow:function(rowIndex){
				var lastIndex = $('#<?php echo $ls_gridname; ?>').data('selectedIndex');
				$('#<?php echo $ls_gridname; ?>').data('selectedIndex', rowIndex);
			},
			onLoadSuccess:function(){ }
		});
	});
	
</script>
<table id="<?php echo $ls_gridname; ?>" style="width:600;height:auto" singleSelect="true" idField="urutan" showFooter="true">
<thead>
    <tr>
        <th field="tanggal_pembayaran" width="100">Barcode</th>
        <th field="nama_tenant" width="175">Kode - Nama Barang</th>
        <th field="no_tenant" width="100">Jumlah Pesanan</th>
        <th field="biaya_tagihan" width="100">Jumlah Kirim</th>
        <th field="keterangan" width="100">Harga Poko</th>
        <th field="keterangan" width="100">Harga Jual</th>
        <th field="keterangan" width="100">Diskon</th>
        <th field="keterangan" width="100">PPN</th>
        <th field="keterangan" width="100">Terima</th>
        <th field="keterangan" width="100">Catatan</th>
        <!--<th field="qty_order" width="120" align="right" formatter="formatNumericPoint2">Jumlah</th>-->
    </tr>
</thead>
</table>
